package br.com.drestranho.escola.dao;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;

import br.com.drestranho.escola.entity.Avaliacao;

@Stateless
public class AvaliacaoDAO{
    @PersistenceContext(unitName="H6Escola")
    private EntityManager em;
    
    public void salvar(Avaliacao bean){
        em.persist(bean);
    }
    
    public void atualizar(Avaliacao bean){
        em.persist(bean);
    }
    
    public void remover(Avaliacao bean){
        em.persist(bean);
    }
    
    public Avaliacao getBean(Integer Id){
        Avaliacao bean = em.find(Avaliacao.class, Id);
        return bean;
    }
    
    public List<Avaliacao> getBeans(){
        CriteriaBuilder cb = em.getCriteriaBuilder();
        CriteriaQuery<Avaliacao> cq = cb.createQuery(Avaliacao.class);
        Root<Avaliacao> from = cq.from(Avaliacao.class);
        CriteriaQuery<Avaliacao> Select=cq.select(from);
        List<Avaliacao> Chamada = em.createQuery(Select).getResultList();
        return Chamada;
                
    }
    public List<Integer> carregaAnos() {
        Query qry = em.createQuery("select distinct t.ano from Avaliacao t");
        ArrayList<Integer> anos = (ArrayList<Integer>)qry.getResultList();
//        if (funcs.size() > 0) return funcs.get(0);
//        else
        return anos;
    }
    
}